package cn.org.timespace.easyframe.dao.permission.impl;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.hibernate.Query;

import cn.org.timespace.easyframe.dao.EfBaseDAO;
import cn.org.timespace.easyframe.dao.permission.EfRoleControlPointDAO;
import cn.org.timespace.easyframe.model.permission.EfRoleControlPoint;

/**
 * <p>
 * 角色控制点
 * </p>
 * 
 * @version 1.0, 11/02/27
 * @since 1.0
 * @author 
 */

public class EfRoleControlPointDAOImpl extends EfBaseDAO implements EfRoleControlPointDAO{
	
	
	public void save(EfRoleControlPoint transientInstance) {
		log.debug("saving EfRoleControlPoint instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}
	
	public void delete(String roleId) {
		log.debug("deleting EfRoleControlPoint by roleId");
		try {
			StringBuffer deleteSql = new StringBuffer("delete from EfRoleControlPoint a where a.efRole.roleId ='"+roleId+"' ");
			Query q = getSession().createQuery(deleteSql.toString());
			int i = q.executeUpdate();
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}	

	public List<EfRoleControlPoint> findByCondition(String roleId) {
		
		StringBuffer queryString = new StringBuffer("from EfRoleControlPoint a where 1=1");

		if (!StringUtils.isEmpty(roleId)) {
			queryString.append(" and a.efRole.roleId = '"+roleId+"'");
		}

		return getHibernateTemplate().find(queryString.toString());
	}

}